//node是js的运行环境\
// node ./homework/homework16/nodee.js

// console.log("黄紫红会开花)")
// let a = 100
// let b = 150
// let res = a + b
// let fun = () => {
//     console.log("饿了")
// }
// fun()

//fs模块(node自带)
// import fs from "fs";
const fs = require("fs");

fs.appendFile("C:\\aFile.txt", '\nHello i want to sleep.', (err, data) => {
    if (err) {
        throw err;
    }
    console.log('内容已追加到文件');
}); //追加内容

fs.readFile("C:\\aFile.txt", "utf-8", (err, data) => {
    if (err) {
        throw err
        return //不要也行
    }
    console.log(data)
})

//path模块
const path = require("path")
    // console.log(path.sep)
    // let datas = fs.readFileSync("C:" + path.sep + "aFile.txt", "utf-8")
    //没用的拼接
    // let p = path.join("C:", "aFile.txt")

// let p = path.resolve("C:", "aFile.txt")
// console.log(p)

// console.log(path.basename(p)) 
//得到某个路径的文件名
// console.log(path.basename(p, ".txt")) 
//得到某个路径的纯文件名
// console.log(path.dirname(p))
// console.log(path.extname(p))

// let re = path.parse("C:\\Users\\Administrator\\demo_-js\\aFile.txt")
// console.log(re)
// console.log(__dirname)

//http模块
const https = require("http")
const url = require("url")
let server = https.createServer((req, res) => {
    console.log(req)
    if (req.method == "GET") {
        console.log("this is GET")
        console.log(req.url)
        const up = url.parse(req.url, true)
        console.log(up.query.name)
    } else {
        console.log("This is no GET")
    }
    res.end("i want to have my holiday")
})
server.listen(3000, () => {
    console.log("下课铃声监听中")
})